<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>选项卡</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .box {
        width: 300px;
        height: 300px;
        background-color: aqua;
        
      }
     
    </style>
    <script src="../js/vue.js"></script>
  </head>
  <body>
    <div id="root" style="display: flex;">
      <div class="box"  >
        <div v-for="v in arr" :key="v.id">
            <p @click="tab(v.id)">{{v.name}}</p>
            <div>
                    <div v-for="i in v.children" :key="i.id" v-show="type==v.id">
                      {{i.name}}
                  </div>  
            </div>
        
        </div>
           
      </div>
    </div>
    <script>
      Vue.config.productionTip = false;
      new Vue({
        el: "#root",
        data: {
          type: 1,
          arr: [
            {
              id: 1,
              name: "社会新闻",
              children: [
                { id: 2, name: "油价上涨了" },
                { id: 3, name: "该核酸检测了" },
              ],
            },
            {
              id: 4,
              name: "娱乐新闻",
              children: [
                { id: 5, name: "周杰伦发歌了" },
                { id: 6, name: "周杰伦销量第一了" },
              ],
            },
          ],
        },
        methods: {
            tab(v){
                console.log(v);
                this.type=v
            }
        }
      });
    </script>
  </body>
</html>
